﻿namespace DreamBuilder.Common.ServiceProxyFactory
{
    using System;
    using System.Collections;
    using System.ServiceModel;

    internal static class ChannelFactoryCreator
    {
        private static Hashtable channelFactories = new Hashtable();

        public static ChannelFactory<T> Create<T>(string endpointName)
        {
            if (string.IsNullOrEmpty(endpointName))
            {
                throw new ArgumentNullException("endpointName");
            }
            ChannelFactory<T> factory = null;
            if (channelFactories.ContainsKey(endpointName))
            {
                factory = channelFactories[endpointName] as ChannelFactory<T>;
            }
            if (factory == null)
            {
                factory = new ChannelFactory<T>(endpointName);
                lock (channelFactories.SyncRoot)
                {
                    channelFactories[endpointName] = factory;
                }
            }
            return factory;
        }
    }
}

